<style scoped>
/* 审核信息容器 */
.review-info-container {
  padding: 15px;
  background: #f8f8f8;
  border-radius: 4px;
  margin-bottom: 20px;
}

/* 信息行样式 */
.info-row {
  display: flex;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px dashed #e6e6e6;
}

.info-row:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* 信息项样式 */
.info-item {
  flex: 1;
  margin-right: 20px;
  min-width: 200px;
}

.info-item.full-width {
  flex: 2;
}

.info-item label {
  color: #909399;
  font-weight: normal;
  margin-right: 10px;
}

.info-item span {
  color: #606266;
}

/* 备注内容样式 */
.remark-content {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

/* 物料表格容器 */
.material-table-container {
  margin-top: 20px;
}

.add-material-btn {
  margin-bottom: 15px;
}

/* 审核意见区域 */
.audit-comment-container {
  margin-top: 25px;
  padding-top: 15px;
  border-top: 1px solid #ebeef5;
}

.section-title {
  color: #606266;
  margin-bottom: 15px;
  font-size: 16px;
  font-weight: 500;
}

.audit-comment-input {
  width: 100%;
}

/* 表格样式优化 */
.material-table {
  border: 1px solid #ebeef5;
  border-radius: 4px;
}

/* 对话框底部按钮 */
.dialog-footer {
  text-align: right;
  padding: 15px 20px;
  border-top: 1px solid #e6e6e6;
}

/* 表单元素间距调整 */
.el-form-item {
  margin-bottom: 18px;
}
</style>


<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="调拨状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择调拨状态" clearable @keyup.enter.native="handleQuery">
          <el-option label="全部" value=""/>
          <el-option label="待审核" value="0"/>
          <el-option label="通过" value="1"/>
          <el-option label="拒绝" value="2"/>
          <el-option label="完成" value="3"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['storage:allot:add']"
        >申请调拨
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['storage:allot:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="allotList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="调拨单号" align="center" prop="transferNo"/>
      <el-table-column label="调出仓库的库区" align="center">
        <template #default="prop">
        {{prop.row.fromWarehouse.name}}/{{prop.row.fromArea.name}}
        </template >
      </el-table-column>
      <el-table-column label="调入仓库的库区" align="center" >
        <template #default="prop">
          {{prop.row.toWarehouse.name}}/{{prop.row.toArea.name}}
        </template >
      </el-table-column>
      <el-table-column label="调拨类型" align="center" prop="transferType" :formatter="formatInventoryType"/>
      <el-table-column label="计划调拨总数" align="center" prop="totalQuantity"/>
      <el-table-column label="操作人" align="center" prop="sysUser.userName"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="formatStatus"/>
      <el-table-column label="申请时间" align="center" prop="createdAt" width="230px"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAudit(scope.row)"
          >查看详细数据
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" style="max-height: 700px; overflow-y: auto;">
        <!-- 审核模式下的信息展示 -->
        <template v-if="isReviewMode">
          <div class="review-info-container">
            <!-- 第一行：基本信息 -->
            <div class="info-row">
              <div class="info-item">
                <label>调拨单号：</label>
                <span>{{ form.transferNo || '-' }}</span>
              </div>
              <div class="info-item">
                <label>调拨类型：</label>
                <span>{{ form.transferType === 1 ? '正常调拨' : '紧急调拨' }}</span>
              </div>
            </div>

            <!-- 第二行：仓库信息 -->
            <div class="info-row">
              <div class="info-item full-width">
                <label>源仓库/库区：</label>
                <span>{{ form.fromWarehouse.name || '-' }} / {{ form.fromArea.name || '-' }}</span>
              </div>
              <div class="info-item full-width">
                <label>目标仓库/库区：</label>
                <span>{{ form.toWarehouse.name || '-' }} / {{ form.toArea.name || '-' }}</span>
              </div>
            </div>

            <!-- 第三行：数量信息 -->
            <div class="info-row">
              <div class="info-item">
                <label>计划总数：</label>
                <span>{{ form.totalQuantity || '0' }}</span>
              </div>
              <div class="info-item">
                <label>状态：</label>
                <span>{{ formatFormStatus(form.status) }}</span>
              </div>
            </div>


            <!-- 第四行：申请人与审核人信息 -->
            <div class="info-row">
              <div class="info-item">
                <label>申请人：</label>
                <span>{{ form.sysUser.userName || "未知" }}</span>
              </div>
              <div class="info-item">
                <label>审核人：</label>
                <span>{{ form.sysUser2.userName || '-' }}</span>
              </div>
            </div>

            <!-- 第五行：时间信息 -->
            <div class="info-row">
              <div class="info-item">
                <label>申请时间：</label>
                <span>{{ form.createdAt || "-" }}</span>
              </div>
              <div class="info-item">
                <label>调拨审核时间：</label>
                <span>{{ form.updatedAt || "-" }}</span>
              </div>
            </div>

            <!-- 备注 -->
            <div class="info-row">
              <div class="info-item full-width">
                <label>备注：</label>
                <span class="remark-content">{{ form.remark || '无' }}</span>
              </div>
            </div>
          </div>
        </template>

        <!-- 申请模式下的表单 -->
        <template v-else>
          <div style="display: flex;gap: 50px;">
            <el-form-item label="源仓库与源库区" prop="sourceWarehouse">
              <el-cascader
                ref="sourceCascader"
                placeholder="请选择源仓库和源库区"
                v-model="sourceWarehouse"
                :options="fromWarehouseOptions"
                @change="handleSourceChange"
                clearable
              />
            </el-form-item>
            <el-form-item label="目标仓库与目标库区" prop="targetWarehouse" label-width="140px">
              <el-cascader
                placeholder="请选择目标仓库和目标库区"
                v-model="targetWarehouse"
                :options="toWarehouseOptions"
                @change="handleTargetChange"
                clearable
              />
            </el-form-item>
          </div>
          <div style="display: flex;gap: 50px;">
            <el-form-item label="调拨类型" prop="transferType">
              <el-radio-group v-model="form.transferType">
                <el-radio :label="1">正常调拨</el-radio>
                <el-radio :label="2">紧急调拨</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="计划调拨总数" prop="totalQuantity">
              <el-input v-model="form.totalQuantity" placeholder="自动计算" readonly/>
            </el-form-item>
          </div>
          <el-form-item label="备注">
            <el-input
              placeholder="请输入备注"
              type="textarea"
              v-model="form.remark"
              style="width: 650px;"
            />
          </el-form-item>
        </template>

        <!-- 物料表格（共用部分） -->
        <div class="material-table-container">
          <el-button
            type="primary"
            @click="handSelectMaterials"
            v-if="!isReviewMode"
            class="add-material-btn"
          >添加物料
          </el-button>

          <el-table
            :data="selectedMaterials"
            style="width: 100%"
            class="material-table"
            :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
          >
            <el-table-column type="index" label="序号" width="60" align="center"/>
            <el-table-column label="物料名称" prop="material.materialName" align="center"/>
            <el-table-column
              align="center"
              :prop="isReviewMode ? 'erpInventory.quantity' : 'quantity'"
              label="库存数量"
            />
            <el-table-column
              align="center"
              :prop="isReviewMode ? 'erpInventory.lockedQuantity' : 'lockedQuantity'"
              label="锁定数量"
            />
            <el-table-column label="单位" prop="unit" align="center"/>
            <el-table-column label="计划调拨数量" width="150px" align="center">
              <template slot-scope="scope">
                <el-input-number
                  v-if="!isReviewMode"
                  v-model="scope.row.planQuantity"
                  :min="1"
                  :max="scope.row.quantity - scope.row.lockedQuantity"
                  @change="calculateTotalQuantity"
                  style="width: 120px"
                />
                <span v-else>{{ scope.row.planQuantity }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" v-if="!isReviewMode">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="removeMaterial(scope.$index)"
                >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 审核意见（仅在审核模式显示） -->
        <div class="audit-comment-container" v-if="isReviewMode">
          <h4 class="section-title">审核意见</h4>
          <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入审核意见"
            v-model="form.auditOpinion"
            :readonly="form.status !== 0"
            class="audit-comment-input"
          />
        </div>
      </el-form>

      <!-- 底部按钮 -->
      <div slot="footer" class="dialog-footer">
        <!-- 审核模式下显示通过/拒绝按钮 -->
        <template v-if="isReviewMode && form.status === 0">
          <el-button type="success" @click="approveAllot">通过</el-button>
          <el-button type="danger" @click="rejectAllot">拒绝</el-button>
        </template>
        <!-- 申请模式下显示提交按钮 -->
        <el-button type="primary" @click="submitForm" v-if="!isReviewMode">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
        <el-button @click="resetForm" v-if="!isReviewMode">重 置</el-button>
      </div>
    </el-dialog>

    <!--    选择物料弹窗-->
    <el-dialog title="选择物料" :visible.sync="open2" width="800px" append-to-body
               style="overflow: auto;max-height: 700px">
      <el-table ref="multipleTable"
                :data="optionalMaterials"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange2">
        <el-table-column type="selection" width="55"/>
        <el-table-column prop="batchNo" label="批次号" width="120"/>
        <el-table-column prop="material.materialName" label="物料名称" width="120"/>
        <el-table-column prop="quantity" label="库存数量" width="120"/>
        <el-table-column prop="lockedQuantity" label="锁定数量" width="120"/>
        <el-table-column prop="unit" label="单位" width="120"/>
        <el-table-column prop="status" label="状态" width="120" :formatter="formatInventoryStatus"/>
      </el-table>
      <br/>
      <el-button type="primary" @click="confirmSelection">确定</el-button>
    </el-dialog>
  </div>
</template>

<script>
import {listAllot, getAllot, delAllot, addAllot, approveAllot, refuseAllot} from "@/api/storage/allot"
import {getErpWarehouseAndArea} from "@/api/storage/warehouse";
import Dept from "@/views/system/dept/index.vue";
import {listInventory} from "@/api/storage/inventory";

export default {
  name: "Allot",
  components: {Dept},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调拨管理表格数据
      allotList: [],
      // 可选择物料数据
      optionalMaterials: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层(选择物料弹窗)
      open2: false,
      // 控制是否为审核模式
      isReviewMode: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 查询库存参数
      queryInventoryParams: {},
      // 表单参数
      form: {},
      //存储源仓库与源库区数据
      sourceWarehouse: {
        fromWarehouseId: '',
        fromAreaId: '',
      },
      //储存目标仓库与目标库区数据
      targetWarehouse: {
        toWarehouseId: '',
        toAreaId: '',
      },
      // 用于存储源级联选择器的选项数据
      fromWarehouseOptions: [],
      // 用于存储目标级联选择器的选项数据
      toWarehouseOptions: [],
      //存储已选择的物料信息
      selectedMaterials: [],
      //临时存储勾选的物料
      storedMaterials: [],
      // 表单校验
      rules: {
        transferType: [
          {required: true, message: "请选择调拨类型", trigger: "change"}
        ],
      },
      //表单校验
      rules2: {
        planQuantity: [
          {
            required: true,
            message: "计划调拨数量不能为空",
            trigger: "blur"
          },
          {
            type: "number",
            min: 1, // 最小值必须 ≥1
            message: "计划调拨数量必须大于0",
            trigger: "blur"
          },
          {
            validator: (rule, value, callback) => {
              const row = this.selectedMaterials[rule.field.split('.')[2]]; // 获取当前行数据
              if (!row) {
                callback(new Error("无法获取物料数据"));
                return;
              }
              const max = row.quantity - row.lockedQuantity;
              if (value > max) {
                callback(new Error(`调拨数量不能超过可用库存 ${max}`));
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ]
      }
    }
  },
  created() {
    this.getList()
    this.getErpWarehouseAndArea()
  },
  methods: {
    // 格式化状态显示
    formatStatus(row) {
      const statusMap = {
        0: '待审核',
        1: '已通过',
        2: '已拒绝',
        3: '已完成',
      };
      return statusMap[row.status] || row.status;
    },
    // 格式化详情表单状态显示
    formatFormStatus(status) {
      const statusMap = {
        0: '待审核',
        1: '已通过',
        2: '已拒绝',
        3: '已完成',
      };
      return statusMap[status] || status;
    },
    formatInventoryType(row){
      const typeMap = {
        1: '正常调拨',
        2: '紧急调拨',
      };
      return typeMap[row.transferType] || row.transferType;
    },
    //格式化库存状态的显示
    formatInventoryStatus(row) {
      const statusMap = {
        1: '正常',
        2: '待检',
        3: '不良品',
      };
      return statusMap[row.status] || row.status;
    },
    //获取级联选择器中所选源仓库和源库区信息
    handleSourceChange(selectedValues) {
      // 1. 备份当前选择的仓库/库区
      const oldWarehouseId = this.sourceWarehouse.fromWarehouseId;
      const oldAreaId = this.sourceWarehouse.fromAreaId;

      // 2. 检查是否有已选物料
      if (this.selectedMaterials.length > 0) {
        this.$confirm(
          "切换源仓库将清空已选物料，是否继续？",
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        ).then(() => {
          // 用户确认：清空物料并更新仓库
          this.selectedMaterials = [];
          this.form.totalQuantity = 0;
          this.sourceWarehouse.fromWarehouseId = selectedValues[0];
          this.sourceWarehouse.fromAreaId = selectedValues[1];
          this.queryInventoryParams.warehouseId = selectedValues[0];
          this.queryInventoryParams.areaId = selectedValues[1];
          this.$message.info("已清空调拨物料列表");
        }).catch(() => {
          // 用户取消：恢复原来的仓库/库区数据
          this.sourceWarehouse.fromWarehouseId = oldWarehouseId;
          this.sourceWarehouse.fromAreaId = oldAreaId;
          this.$refs.sourceCascader.dropDownVisible = false; // 关闭弹窗
        });
      } else {
        // 无物料时直接更新仓库
        this.sourceWarehouse.fromWarehouseId = selectedValues[0];
        this.sourceWarehouse.fromAreaId = selectedValues[1];
        this.queryInventoryParams.warehouseId = selectedValues[0];
        this.queryInventoryParams.areaId = selectedValues[1];
      }
    },
    //获取级联选择器中所选目标仓库和目标库区信息
    handleTargetChange(selectedValues) {
      this.targetWarehouse.toWarehouseId = selectedValues[0]
      this.targetWarehouse.toAreaId = selectedValues[1]
    },

    // 加载级联选择器的数据
    getErpWarehouseAndArea() {
      getErpWarehouseAndArea().then(res => {
        this.fromWarehouseOptions = res
        this.toWarehouseOptions = res
      }).catch(error => {
        console.error('获取仓库数据失败:', error)
      })
    },

    /** 查询调拨管理列表 */
    getList() {
      this.loading = true
      listAllot(this.queryParams).then(response => {
        this.allotList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.resetForm();
      // this.reset()
    },
    // 表单重置
    reset() {
      // this.form = {
      // id: null,
      // transferNo: null,
      // fromWarehouseId: null,
      // fromAreaId: null,
      // toWarehouseId: null,
      // toAreaId: null,
      // transferType: "1",
      // status: null,
      // totalQuantity: "0",
      // operatorId: null,
      // checkerId: null,
      // checkTime: null,
      // remark: null,
      // createdAt: null,
      // updatedAt: null
      // }
      // this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 勾选可选择的物料信息弹窗层的多选框触发事件
    handleSelectionChange2(val) {
      this.storedMaterials = val;
    },

    /** 申请审核按钮操作 */
    handleAdd() {
      this.reset()
      this.resetForm();
      this.isReviewMode = false;
      this.open = true
      this.title = "添加调拨管理"
    },
    /** 通过调拨申请 */
    approveAllot() {
      this.$confirm('确定要通过此调拨申请吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        approveAllot(this.form).then(() => {
          this.$message.success('调拨申请已通过');
          this.open = false;
          this.getList();
        })
          .catch(error => {
            console.error('审核通过失败:', error);
            this.$message.error(error.message || '审核通过失败');
          }).finally(() => {
          this.loading = false;
        });
      }).catch(() => {
        // 用户取消操作
      });
    },

    /** 拒绝调拨申请 */
    rejectAllot() {
      this.$confirm('确定要拒绝此调拨申请吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        refuseAllot(this.form).then(() => {
          this.$message.success('调拨申请已拒绝');
          this.open = false;
          this.getList();
        }).catch(error => {
            console.error('审核拒绝失败:', error);
            this.$message.error(error.message || '审核拒绝失败');
          }).finally(() => {
          this.loading = false;
        });
      }).catch(() => {
        // 用户取消操作
      });
    },

    // 点击“添加物料"按钮触发事件
    handSelectMaterials() {
      // 1. 检查是否已选择源仓库和库区
      if (!this.sourceWarehouse.fromWarehouseId || !this.sourceWarehouse.fromAreaId) {
        this.$message.error("请先选择源仓库和源库区");
        return;
      }

      // 2. 打开弹窗并加载可选物料
      this.open2 = true;
      this.loading = true;
      listInventory({
        warehouseId: this.sourceWarehouse.fromWarehouseId,
        areaId: this.sourceWarehouse.fromAreaId
      }).then(response => {
        this.optionalMaterials = response.rows;
        console.log('this.optionalMaterials：',this.optionalMaterials);
      }).finally(() => {
        this.loading = false;
      });
    },
    //选择物料弹窗层点击"确定"按钮触发事件
    confirmSelection() {
      // 处理选中的数据
      const newMaterials = this.storedMaterials.map(item => ({
        ...item,
        planQuantity: 0
      }));

      // 合并到主表格（去重）
      newMaterials.forEach(newItem => {
        const exists = this.selectedMaterials.some(
          item => item.batchNo === newItem.batchNo
        );
        if (!exists) {
          this.selectedMaterials.push(newItem);
        }
      });
      this.open2 = false

      // 清空临时存储
      this.storedMaterials = [];
      // 计算总调拨数量
      this.calculateTotalQuantity();
    },

    // 计算计划调拨总数
    calculateTotalQuantity() {
      this.$nextTick(() => {
        this.form.totalQuantity = this.selectedMaterials.reduce(
          (total, item) => total + (Number(item.planQuantity) || 0),
          0
        );
      });
    },

    // 重置已选物料表单数据
    resetForm() {
      this.form = {
        transferType: 1,
        totalQuantity: 0,
        sysUser: {
          userName: "",
        },
        sysUser2: {
          userName: "",
        },
        toWarehouse: {
          name: '',
        },
        fromWarehouse: {
          name: '',
        },
        fromArea: {
          name: '',
        },
        toArea: {
          name: ''
        }

      };
      this.sourceWarehouse = ''
      this.targetWarehouse = ''
      // 清空已选物料列表
      this.selectedMaterials = [];

      // 重置表单验证状态（需要等待DOM更新）
      this.$nextTick(() => {
        this.$refs.form.resetFields();
        // this.$refs.childComponent?.form2?.resetFields(); // 通过子组件ref访问
      });
    },
    // 删除已选择的物料
    removeMaterial(index) {
      this.selectedMaterials.splice(index, 1);
      this.calculateTotalQuantity();
    },
    // /** 审核按钮操作 */
    handleAudit(row) {
      this.reset()
      const id = row.id || this.ids
      getAllot(id).then(response => {
        this.form = response.data
        this.sourceWarehouse = [this.form.fromWarehouseId, this.form.fromAreaId]
        this.targetWarehouse = [this.form.toWarehouseId, this.form.toAreaId]
        this.transferType = this.form.transferType
        this.isReviewMode = true;
        this.selectedMaterials = this.form.detailList;
        this.open = true
        this.title = "审核调拨"
      })
    },
    /** 提交按钮 */
    submitForm() {
      // 1. 检查目标仓库/库区是否填写
      if (!this.targetWarehouse.toWarehouseId || !this.targetWarehouse.toAreaId) {
        this.$message.error("请选择目标仓库和目标库区");
        return;
      }

      // 2. 检查源和目标是否相同
      if (
        this.sourceWarehouse.fromWarehouseId === this.targetWarehouse.toWarehouseId &&
        this.sourceWarehouse.fromAreaId === this.targetWarehouse.toAreaId
      ) {
        this.$message.error("目标仓库/库区不能与源仓库/库区相同");
        return;
      }

      // 3. 检查调拨类型
      if (!this.form.transferType) {
        this.form.transferType = "1"; // 默认正常调拨
      }

      // 4. 检查物料数量
      if (this.selectedMaterials.some(item => item.planQuantity <= 0)) {
        this.$message.error("所有物料的调拨数量必须大于0");
        return;
      }

      // 5. 提交表单
      this.$refs.form.validate(valid => {
        if (valid) {
          const submitData = {
            ...this.form,
            fromWarehouseId: this.sourceWarehouse.fromWarehouseId,
            fromAreaId: this.sourceWarehouse.fromAreaId,
            toWarehouseId: this.targetWarehouse.toWarehouseId,
            toAreaId: this.targetWarehouse.toAreaId,
            detailList: this.selectedMaterials.map(item => ({
              id: item.id,
              materialId: item.material.id,
              planQuantity: item.planQuantity,
              unit: item.unit
            }))
          };
          addAllot(submitData).then(() => {
            this.$message.success("提交成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除调拨管理编号为"' + ids + '"的数据项？').then(function () {
        return delAllot(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('storage/allot/export', {
        ...this.queryParams
      }, `allot_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

